<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace common\behavior;


use support\Db;

/**
 * 行为扩展：删除task_relation_分表
 */
class TaskRelationProjectTableDeleteEventBehavior
{

    /**
     * 删除 task_relation 分表
     * @param $params
     * @return void
     * @throws \Exception
     */
    public function run(&$params)
    {
        if (empty($params['id'])) {
            return;
        }
        $projectId = $params['id'];
        $newTableName = sprintf('task_relation_project_%d', $projectId);
        // 判断表是否存在
        $tableIsExists = Db::query('SHOW TABLES LIKE ' . "'$newTableName'");
        if (empty($tableIsExists)) {
            return;
        }
        $tmpDeletePartitionTableListSql = sprintf('drop table %s', $newTableName);
        db::execute($tmpDeletePartitionTableListSql);
    }

}
